/*
 * Copyright 2012 dev.takayuki@gmail.com All Rights Reserved.
 */

package dev.takayuki.android.calculator.core;

import java.util.Stack;

public class ParamStack {
	private Stack<Param> iStack;

	public ParamStack() {
		iStack = new Stack<Param>();
	}

	public void push(Param param) {
		int type = param.getType();

		if (iStack.empty()) {
			if (Param.TYPE_NUMBER != type) {
				throw new IllegalArgumentException();
			}
			iStack.push(param);
			return;
		}

		int prev_type = iStack.peek().getType();
		if (Param.TYPE_NUMBER == type && Param.TYPE_NUMBER == prev_type) {
			throw new IllegalArgumentException();
		} else if(Param.TYPE_NUMBER != type && Param.TYPE_NUMBER != prev_type) {
			throw new IllegalArgumentException();
		}
		iStack.push(param);
	}

	Param pop() {
		Param param = null;

		if (!iStack.isEmpty()) {
			param = iStack.pop();
		}
		return param;
	}
}